//
//  FairyGameAppDelegate.m
//  FairyGame
//
//  Created by 李 世宸 on 2009/7/31.
//  Copyright __MyCompanyName__ 2009. All rights reserved.
//

#import "FairyGameAppDelegate.h"
#import "CreditTitlesLayer.h"

@implementation FairyGameAppDelegate

// window is a property. @synthesize will create the accesors methods
@synthesize window;

// Application entry point
- (void)applicationDidFinishLaunching:(UIApplication *)application {    

	// create an initilize the main UIWindow
	window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
	
	// Attach cocos2d to the window
	[[Director sharedDirector] attachInWindow:window];
	
	// before creating any layer, set the landscape(前景) mode 橫躺/直立
	[[Director sharedDirector] setDeviceOrientation:CCDeviceOrientationLandscapeLeft];
	
	// display FPS (useful when debugging)
	[[Director sharedDirector] setDisplayFPS:YES];
	
	// frames per second
	[[Director sharedDirector] setAnimationInterval:1.0/60];
	
	// Make the window visible
	[window makeKeyAndVisible];
	
	// Create and initialize parent and empty Scene
	Scene *scene = [Scene node];
	
	// Create and initialize our HelloWorld Layer
	Layer *layer = [CreditTitles node];
	
	// add our HelloWorld Layer as a child of the main scene
	[scene addChild:layer];
	
	// Run!
	[[Director sharedDirector] runWithScene: scene];
}

// getting a call, pause the game
-(void) applicationWillResignActive:(UIApplication *)application
{
	[[Director sharedDirector] pause];
}

// call got rejected
-(void) applicationDidBecomeActive:(UIApplication *)application
{
	[[Director sharedDirector] resume];
}

// purge memroy
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
	[[TextureMgr sharedTextureMgr] removeAllTextures];
}

// next delta time will be zero
-(void) applicationSignificantTimeChange:(UIApplication *)application
{
	[[Director sharedDirector] setNextDeltaTimeZero:YES];
}

- (void)dealloc {
    [window release];
    [super dealloc];
}


@end
